<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<script type="text/javascript">
			//			1. 有段文字text = "and in it he says Any damn fool could", 不改变原text的前提下， 提取第一段话a = "Any damn fool could", 第二段话b = "and", 第三段话c = "could", 注意， slice() 可以接受负数, string.slice().
							var old_text = "and in it he says Any damn fool could";
							var new_text1 = old_text.substr(old_text.lastIndexOf("A"),old_text.length);
							var new_text2 = old_text.slice(0,3);
							var new_text3 = old_text.slice(-5);
							console.log(new_text1);
							console.log(new_text2);
							console.log(new_text3);
			//			2. 字符串digite = "0123456789", 把前5个字符分割出来， 返回个单字符的数组, 注意， 返回数组里面的数字是字符串类型, string.split()
							var digite = "0123456789";
							var digite_arr = digite.slice(0,5).split("");
							console.log(digite_arr);
			//3.已知有字符串foo=”get-element-by-id”,写一个function将其转化成驼峰表示法”getElementById”.
				function first_big(str){
					var new_str = str.split("-");
					var arr = [];
					for(var i =1;i<new_str.length;i++){
						var big = new_str[i].split("")[0].toUpperCase();
						var small = new_str[i].slice(1,new_str[i].length);
						var a = big+small;
						arr.push(a);
					}
					return new_str[0] + arr.join("");
				}
				console.log(first_big("get-element-by-id"));
			//4.定义一个函数,将"今天是什么鬼天气，这么热，明天要去游泳！"里面的有"天"的下标输出(用indexof())
			var today = "今天是什么鬼天气，这么热，明天要去游泳！";
				function fn1(ele){
					var today_json = {};
					for(var i = 0;i<ele.length;i++){
						var str222 = ele[i];
						if(!today_json[str222]++){
							today_json[str222] = 1;
						}
					}
					return today_json;
				}
				console.log(fn1(today)["天"]);
			//5.定义一个函数,将"今天是什么鬼天气，这么热，明天要去游泳！"里面的有"天"替换成"日"(用replace())
				function tihuan(str){
					var new_str = str.replace(/天/g,"日");
					return new_str;
				}
				console.log(tihuan(today));
			//6.移除数组 arr[1, 2, 3, 4, 2] 中的2。不要直接修改数组 arr，结果返回新的数组
			var arr213 = [1, 2, 3, 4, 2];
			var new_arr123 = [];
			for(var i = 0;i<arr213.length;i++){
				if(arr213[i] == 2){
					continue;
				}
				new_arr123.push(arr213[i]);
			}
			console.log(new_arr123);
			//7.定义一个函数,能在数组 arr[1, 2, 3, 4, 2] 的 "2"后面添加元素 "Melon"。不要直接修改数组 arr，结果返回新的数组
			var new_arr111 = [];
			for(var i =0;i<arr213.length;i++){
				if(arr213[i] == 2){
					arr213[i] += "melon";
				}
				new_arr111.push(arr213[i]);
			}
			console.log(new_arr111);
			//8.统计数组 arr[1, 2, 3, 4, 2] 中2出现的次数
				var num_arr = [1,2,3,4,2];
				console.log(fn1(num_arr)[2]);
			//9.找出数组 arr[1, 2, 3, "melon", 4, "melon", 2, 4, "melon"] 中重复出现过的元素,并用数组将重复元素装起来输出
				console.log(fn1([1, 2, 3, "melon", 4, "melon", 2, 4, "melon"]));
			//10.在arr里面输出年龄小于17的对象
						var arr_ha = [
							{ name: "111", sex: "boy", age: 18 },
							{ name: "222", sex: "girl", age: 17 },
							{ name: "333", sex: "boy", age: 16 },
							{ name: "444", sex: "girl", age: 15 },
							{ name: "555", sex: "boy", age: 20 }
						]
						var json_arr = [];
						for(var i = 0;i<arr_ha.length;i++){
							if(arr_ha[i].age<17){
								json_arr.push(arr_ha[i]);
							}
						}
						console.log(json_arr);
		</script>
	</body>

</html>